package team.dmh.wx.exception;


import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import team.dmh.wx.util.Result;
import team.dmh.wx.util.ResultUtils;

/**
 * @Auther: Hz1kai
 * @Date: 2018/9/23 16:44
 * @Description:
 */
@RestControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(value = {RuntimeException.class})
    public Result handleWithRuntimeException(Exception e) {
        if (e instanceof MyException) {
            MyException myException = (MyException) e;
            return ResultUtils.fail(myException.getMessage());
        } else if (e instanceof NullPointerException) {
            e.printStackTrace();
            return ResultUtils.fail(ExceptionEnum.NULL_POINTER.getMessage());
        } else {
            e.printStackTrace();
            return ResultUtils.fail(ExceptionEnum.UNKNOWN.getMessage());
        }
    }

}
